<template>
	<view class="content">
		<view class="uni-container statistics_bg">
			<view class="uni-flex uni-row" style="display: flex;flex-direction: row;justify-content: space-between;">
				<view class="text">库存</view>
			</view>
			<uni-table ref="table" :loading="loading" border stripe>
				<uni-tr>
					<uni-th align="center">类别</uni-th>
					
					<uni-th align="center">产品名称</uni-th>
						<uni-th align="center">库存数量</uni-th>
					<uni-th align="center">产品编码</uni-th>
					<uni-th align="center">规格/型号</uni-th>
					<uni-th align="center">单位</uni-th>
				
					<uni-th align="center">上月出库数量</uni-th>
				</uni-tr>
				<uni-tr v-for="(item, index) in tableData" :key="index">
					<uni-td align="center">{{ item.f_ckmc }}</uni-td>
					<uni-td align="center">
						<view class="name">{{ item.f_wlmc }}</view>
					</uni-td>
										<uni-td align="center">{{ item.f_ckmc === '通用 非核算仓' ? item.erpsl : item.sl }}</uni-td>
					<uni-td align="center">{{ item.f_wlbm }}</uni-td>
					<uni-td align="center">{{ item.f_gg }}</uni-td>
					<uni-td align="center">{{ item.f_dw }}</uni-td>

			        <uni-td align="center">{{ item.lastMonthOutQty }}</uni-td>     
				</uni-tr>
			</uni-table>
<view class="uni-pagination-box"><uni-pagination show-icon :page-size="pageSize" :current="pageCurrent" :total="total" @change="change" /></view>
		</view>


	</view>
</template>

<script>
	import {
		GetInventoryData
	} from '../../common/inventorydetail_api.js'
	import * as util from '../../common/util.js'

	export default {
		data() {
			return {
				dataArray:[],
				tableData:{},
				pageSize: 10,
				pageCurrent: 1,
				loading: false,
				total: 0,
				opts: {

				}

			}
		},
		onReady() {

			uni.setNavigationBarTitle({
				title: "库存"
			})
			this.loadData();
		},



		methods: {
			loadData() {
				
				GetInventoryData().then(res => {
					var array = [];
					for (var i = 0; i < res.length; i++) {
						var item = res[i];
						array.push(item);
					}
					this.dataArray = array;
					this.getData(1);
				});

			},
			change(e) {
				// 分页触发
				this.$refs.table.clearSelection()
				this.getData(e.current)
			},
getData(pageCurrent, value = ''){
				console.log("pageCurrent:" + pageCurrent);
				this.loading = true
				this.pageCurrent = pageCurrent
				
				util.getPageData({
					srcData: this.dataArray,
					pageSize: this.pageSize,
					pageCurrent: pageCurrent,
					value: value,
					success: res => {
						console.log('data', res);
						this.tableData = res.data
						this.total = res.total
						this.loading = false
					}
				})
			},
		},
	}
</script>

<style>
	@import url("inventorydetail.css");
</style>